/*
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.chimos.property.compiler;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

/**
 * @author Niklas Hofmann
 */
public class AntTask extends Task {

    private File directory;
    
    public void setDirectory(File d) {
        directory = d;
    }
    
    private String serialization = Config.Serialization.JAXB.toString();
    
    public void setSerialization(String value)
    {
        serialization = value;
    }
    
    private String protocol = Config.Protocol.JAVAFX.toString();
    
    public void setProtocol(String value)
    {
        protocol = value;
    }
    
    private boolean dummyFields = true;
    
    public void setDummyFields(boolean value)
    {
    	dummyFields = value;
    }

    public @Override
    void execute() throws BuildException {
        try {
            CompilerTask.run
                    (
                        directory,
                        new Config
                            (
                                Config.Serialization.valueOf(serialization),
                                Config.Protocol.valueOf(protocol),
                                dummyFields
                            )
                    );
        } catch (Exception ex) {
            Logger.getLogger(AntTask.class.getName()).log(Level.SEVERE, null, ex);
            throw new BuildException(ex);
        }
    }
}
